import Vue from 'vue'
import VueRouter from 'vue-router'



Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'home',
    meta: { title: "首页" },
    component: () => import('../views/Home.vue'),
    children: [
      {
        path: '/home/classify',
        name: 'classify',
        meta: { title: "分类" },
        component: () => import('../views/home/Classify.vue')
      },
      {
        path: '/home/hompage',
        name: 'hompage',
        meta: { title: "首页" },
        component: () => import('../views/home/HomePage.vue')
      },
      {
        path: '/home/Manifest',
        name: 'Manifest',
        meta: { title: "必选清单" },
        component: () => import('../views/home/Manifest.vue')
      },
      {
        path: '/home/ShoppingCart',
        name: 'ShoppingCart',
        meta: { title: "购物车" },
        component: () => import('../views/home/ShoppingCart.vue')
      },
      {
        path: '/home/My',
        name: 'My',
        meta: { title: "我的易购" },
        component: () => import('../views/home/My.vue')
      },
      {
        path: '/home/',
        redirect: "/home/hompage",
      },
    ]
  },
  {
    path: '/Address',
    name: 'Address',
    meta: { title: "地址" },
    component: () => import('../views/Address.vue')
  },
  {
    path: '/Detail',
    name: 'Detail',
    meta: { title: "详情" },
    component: () => import('../views/Detail.vue')
  },
  {
    path: '/Login',
    name: 'Login',
    meta: { title: "登录" },
    component: () => import('../views/Login.vue')
  },
  {
    path: '/NewAddress',
    name: 'NewAddress',
    meta: { title: "新增地址" },
    component: () => import('../views/New_address.vue')
  },
  {
    path: '/Orders',
    name: 'Orders',
    meta: { title: "我的订单" },
    component: () => import('../views/Orders.vue'),
    children: [
      {
        path: '/Orders/Myorder',
        name: 'Myorder',
        meta: { title: "我的订单" },
        component: () => import('../views/Ordered/MyOrder.vue')
      },
      {
        path: '/Orders/Other',
        name: 'Other',
        meta: { title: "其他订单" },
        component: () => import('../views/Ordered/OthersOrder.vue')
      },
      {
        path: '/Orders/',
        redirect: '/Orders/Myorder',
      }
    ]
  },
  {
    path: '/PrivateInformation',
    name: 'PrivateInformation',
    meta: { title: "个人信息" },
    component: () => import('../views/Private_Information.vue')
  },
  {
    path: '/Search',
    name: 'Search',
    meta: { title: "搜索" },
    component: () => import('../views/Search.vue'),
    children: [
      {
        path: '/Search/HortSearch',
        name: 'HortSearch',
        meta: { title: "热门搜索" },
        component: () => import('../components/search/HortSearch.vue')
      },
      {
        path: '/Search/SearchSort',
        name: 'SearchSort',
        meta: { title: "搜索排序" },
        component: () => import('../components/search/SearchSort.vue')
      },
      {
        path: '/Search/',
        redirect: '/Search/HortSearch'
      }
    ]
  },
  {
    path: '/StoreAttention',
    name: 'StoreAttention',
    meta: { title: "店铺关注" },
    component: () => import('../views/Store_attention.vue')
  },
  {
    path: '/UserSet',
    name: 'UserSet',
    meta: { title: "用户设置" },
    component: () => import('../views/UserSet.vue')
  },
  {
    path: '/Personal',
    name: 'Personal',
    meta: { title: "个人信息" },
    component: () => import('../views/Personal.vue')
  },
  {
    path: '/NameViw',
    name: 'NameViw',
    meta: { title: "昵称" },
    component: () => import('../views/NameView.vue')
  },
  {//路由重定向
    path: '/',
    redirect: "/home",
  },
  {//404
    path: "*",
    name: "NotFound",
    component: () => import('../views/NotFound.vue')
  }
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//路由守卫函数
router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next();
})


export default router
